package com.shushan.home.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;


import com.shushan.shushanbao.R;

import java.util.List;

/**
 * @ClassName: GuidePagerAdapter
 * @Desciption: //引导页viewpager适配器
 * @author: zhangshihao
 * @date: 2018-04-03
 */
public class GuidePagerAdapter extends PagerAdapter {

    private List<Integer> imgResIdList;
    private List<Integer> textResIdList;
    private Context context;

    public GuidePagerAdapter(Context context,List<Integer> imgResIdList,List<Integer> textResIdList){
        this.context = context;
        this.imgResIdList = imgResIdList;
        this.textResIdList = textResIdList;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_guide_pager_adapter,null,false);
        ImageView ivPagerImg = view.findViewById(R.id.iv_pager_img);
        ivPagerImg.setImageResource(imgResIdList.get(position));
        ImageView ivPagerText = view.findViewById(R.id.iv_pager_text);
        ivPagerText.setImageResource(textResIdList.get(position));
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public int getCount() {
        return imgResIdList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
}
